<?php
header("Content-type: text/html; charset=utf-8");
//引入数据库
$db_data = include './caiji_db.php';

$arr_content = array(); //用一个空数组接收数据
foreach ($db_data as $key => $value) { //遍历数组中的每一个数组
	$file_content = file_get_contents($value['positionId__url']); //读取文件中指定属性的值
	// var_dump($file_content);	
	$rule_workname_pattern = "/<h1\stitle=\"(.+)\">/"; //匹配正则
	$rule_detail_pattern = "/<span(.*)>(.+)<\/span>/";
    preg_match($rule_workname_pattern,$file_content,$match); //用第三个参数接收得到的值，

    preg_match_all($rule_detail_pattern,$file_content,$match_detail);
    // var_dump($match_detail);
    $value['positionId__url'] = $value['positionId__url']; //存放入关联数组中
    // var_dump($match);
    $value['work_name'] = $match[1];
    // var_dump($match_detail[2][10]);
    $value['salary'] = $match_detail[2][10];//抓取对应的薪水
    $value['city'] = $match_detail[2][11];
    $value['experience'] = $match_detail[2][12];
    $value['edu'] = $match_detail[2][13];
    $value['time'] = $match_detail[2][14];
    //$result = preg_replace($rule_pattern,'\1',$match[0]);
	// var_dump($value);
    array_push($arr_content, $value); //将得到的数组丢到数据库中
    // var_dump($arr_content);
    // exit();
    $newDb = var_export($arr_content,TRUE);//将数组变成字符串，以便能存进数据库里
    $newDb2 ="<?php  return $newDb ?>";  //重新组合成PHP形式的数组
    // var_dump($newDb2);
    //将其保存到数据库里的db.php
    // file_put_contents('./detail_db.php',$newDb2);  //这样会将每个遍历过的值都插入一遍，错误
}

   $newDb2 ="<?php  return $newDb ?>"; //转成PHP格式字符串
   file_put_contents('./detail_db.php',$newDb2); //将其保存到数据库里的db.php
    // var_dump($db_data);


?> 